<?php
class CollectcategoryModel extends Model {
	protected $_validate = array(
	    array('title','require','请填写标题！'),
    );
	protected $_auto = array(
        array('datetime','time',1,'function'),
		array('datetime','time',2,'function'),
    );
	public function getListToArray($pid=0){
		$re=$this->where('pid='.$pid)->order('sort')->select();
		if($re!==false){
			foreach($re as $k=>$v){
				$re[$k]['sub']=$this->getListToArray($v['id']);
			}
			return $re;
		}
	}
	
	public function getListToArray1($pid=0,$deep=0,$arr=array()){
		$re=$this->where(array('pid'=>$pid))->order('sort')->select();
		if($re!==false){
			$deep++;
			foreach($re as $k=>$v){
				$v['deep']=$deep;
				$arr[]=$v;
				$arr=$this->getListToArray1($v['id'],$deep,$arr);
			}
			return $arr;
		}
	}
	public function getAllIDBypid($pid,$includeself=true){
		$arr = $this->getListToArray1($pid);
		$data = array();
		foreach($arr as $k=>$v){
			$data[]=$v['id']; 
		}
		if($includeself){
			$data[]=$pid;
		}
		return $data;
	}
}